#include "MapTab.hpp"

MapTab::MapTab(EditorInstance* inst):Panel(0, 0, 100, 19, Panel::BindBottom){

    instance = inst;

    sf::Color bgColor = sf::Color::Black;
    bgColor.a = 205;
    background.setFillColor(bgColor);
    add(&background);

    name.setPosition(5, 2);
    name.setString(12, sf::Color::White, sf::Text::Regular, "");
    add(&name);

    closeButton = new IconButton(0, 4, 12, 12, 0);
    add(closeButton);
    updateName();
}

/** 
* Update the name Label of this tab to current Map name.
*/
void MapTab::updateName(){
    name.setString(instance->map->name);
    closeButton->rect.left = name.labelText.getLocalBounds().width + 10;
    rect.width = name.labelText.getLocalBounds().width + 27;
    background.setSize(sf::Vector2f(rect.width, rect.height));
}

InterfaceElement* MapTab::collisionCheck(int x, int y){
    InterfaceElement* clicked = Panel::collisionCheck(x, y);
    if(clicked != 0){
        return clicked;
    }
    
    return InterfaceElement::collisionCheck(x, y);
}